<template>
  <div>
    <!-- 使用element-ui的 -->
    <!-- :unique-opened=true  是否只保持一个子菜单的展开 -->
    <!-- :router=true   是否使用 vue-router 的模式，启用该模式会在激活导航时以 index 作为 path 进行路由跳转 -->
    <el-container>
      <el-aside width="200px">
        <el-col>
          <el-menu
            :unique-opened="true"
            :router="true"
            default-active="home"
            class="el-menu-vertical-demo"
            background-color="#20222A"
            text-color="#fff"
            active-text-color="#ffd04b"
          >
            <el-menu-item index="home">
              <i class="el-icon-menu"></i>
              <span slot="title">首页</span>
            </el-menu-item>

            <el-submenu
              :index="'' + item.id"
              v-for="item in list"
              :key="item.id"
            >
              <template slot="title">
                <i :class="item.icon"></i>
                <span>{{ item.title }}</span>
              </template>
              <el-menu-item
                :index="k.url"
                v-for="k in item.children"
                :key="k.id"
                >{{ k.title }}</el-menu-item
              >
            </el-submenu>

            <!-- <el-submenu index="3">
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>商城管理</span>
              </template>
              <el-menu-item index="3-1">商城分类</el-menu-item>
              <el-menu-item index="3-2">商品规格</el-menu-item>
              <el-menu-item index="3-3">商品管理</el-menu-item>
              <el-menu-item index="3-4">会员管理</el-menu-item>
              <el-menu-item index="3-5">轮播图管理</el-menu-item>
              <el-menu-item index="3-6">秒杀活动</el-menu-item>
            </el-submenu> -->
          </el-menu>
        </el-col>
      </el-aside>
      <el-container>
        <el-header
          >欢迎您&nbsp; <span>{{ userManger?userManger.username:'' }}</span> &nbsp;<a
            href="javascript:;"
           @click="logouting"
            >退出登录<i clas0s="el-icon-setting"></i></a
        ></el-header>

        <el-main>
          <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>{{ $route.meta.title }}</el-breadcrumb-item>
          </el-breadcrumb>
          <!-- 设置二级路由出口 -->
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { mapGetters, mapActions } from "vuex";
export default {
  data() {
    return {
      list: [],
    };
  },
  methods: {
    logouting() {
      this.logout(this)
    },
      ...mapActions({
      getUserInfo:'login/getUserInfo',
      logout:'login/logout'
    })
  },
  computed: {
    ...mapGetters({
      userManger: "login/userManger",
    }),
  },
  mounted() {
    this.list = localStorage['userManger']?JSON.parse(localStorage['userManger']).menus:[]
    this.getUserInfo(this.userManger)
  },
};
</script>

<style scoped>
.el-container {
  width: 100vw;
  height: 100vh;
}
.el-aside {
  background-color: #20222a;
}
.el-header {
  background-color: #b3c0d1;
}
::v-deep .el-header {
  padding-top: 20px;
  text-align: right;
}
::v-deep .el-header span {
  color: black;
  font-weight: bold;
  font-size: 20px;
}
</style>